package ltd.sshine.networkhelper.autoconfigure;

import lombok.Data;
import ltd.sshine.networkclient.config.ClientConfig;
import ltd.sshine.networkclient.config.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment;

@Data
@Lazy //确保获取到服务器端口
@ConfigurationProperties(prefix = "network")
public class NetworkHelperProperties {
    private ServerConfig server;
    private ClientConfig client;
    @Autowired
    public NetworkHelperProperties(Environment environment) {
        Integer port = environment.getProperty("server.port",Integer.class);
        this.server = new ServerConfig();
        this.client = new ClientConfig();
        if (port != null)
            client.setPort(port);
    }
}
